import apiClient from "../apiClient";

export interface LoginByPasswordReq {
	mobile: string;
	password: string;
}

export interface LoginBySmsReq {
	mobile: string;
	code: string;
}

export interface LoginResult {
	token: string;
}

export interface RegisterReq {
	companyName: string;
	remark?: string;
	name: string;
	mobile: string;
	password: string;
	code: string;
}

/**
 * 密码登录
 */
export const loginByPassword = (data: LoginByPasswordReq) => {
	return apiClient.post<LoginResult>({
		url: "/login/password",
		data,
	});
};

/**
 * 验证码登录
 */
export const loginBySms = (data: LoginBySmsReq) => {
	return apiClient.post<LoginResult>({
		url: "/login/sms",
		data,
	});
};

/**
 * 获取短信验证码
 */
export const getSmsCode = (mobile: string, event = "register") => {
	return apiClient.post({
		url: "/sms/send",
		data: { mobile, event },
	});
};

/**
 * 注册
 */
export const register = (data: RegisterReq) => {
	return apiClient.post<void>({
		url: "/login/reg",
		data,
	});
};

export const resetPassword = (data: any) => {
	return apiClient.post<void>({
		url: "/login/resetPasswordByMobile",
		data,
	});
};
